********************************************************************************
**      TITLE: Data Preparation for SSN resarch of a2i
**
**      PROJECT: Information and power asymmetry in digitalised SSN system
**
**      PURPOSE: Identifying and creating variables necessary to analyse 
**		information and power asymmetry in digitalised SSN system
**
**      CREATED: 14 July 2022 | Time: 12:32 pm
**
**                                                                                                      
********************************************************************************




**# Setup Stata
*------------------------------------------------------------------------------*
        
        cls
        clear                   all
        macro drop              _all
        version                 14
        set min_memory  		1g 
        set maxvar              32767
        set more                off
        discard 
        set seed                87235
        set sortseed    98237
        set niceness    1
        set traced              1
        pause                   on
        
		
		/*Set the folder structure in the following manner to have the do files
		run properly:
		
		1. Codes -> Subfolder "01_Ado". Put all the do files in Codes
		
		2. Data -> Subfolder "Raw" and "Clean"
		
		Place the dataset "a2i_SSN" in "Raw"
		*/
		
		
		  **# Global Path
        *------------------------------------------------------------------------------*
                
        * Setup working directory
        *------------------------
                if "$cwd" ~= "" cd "$cwd"
                else global cwd "`c(pwd)'"
                sysdir set PLUS "01_Ado/"
				

use "../Data/Raw/a2i_SSN.dta", replace


				


		



/*cleaning the household ids because there are doubles in the given hh ids 
which may cause problems while analyzing the data*/

recode q_a 1=521 if q_j==15
recode q_a 2=522 if q_j==72
recode q_a 121=523 if q_j==42
recode q_a 143=144 if q_j==72

recode q_a 223=221 if q_j==65
recode q_a 269=524 if q_j==13
recode q_a 270=525 if q_j==85
recode q_a 271=526 if q_j==51
recode q_a 327=527 if q_j==66
recode q_a 328=528 if q_j==80
recode q_a 329=529 if q_j==81
recode q_a 330=530 if q_j==80
recode q_a 331=531 if q_j==21
recode q_a 332=532 if q_j==12
recode q_a 401=533 if q_j==65
recode q_a 402=534 if q_j==40
recode q_a 403=535 if q_j==75
recode q_a 440=536 if q_j==70
recode q_a 441=537 if q_j==67
recode q_a 442=538 if q_j==45
recode q_a 443=539 if q_j==45
recode q_a 444=540 if q_j==72
recode q_a 445=541 if q_j==21
recode q_a 446=542 if q_j==14
recode q_a 447=543 if q_j==18
recode q_a 447=544 if q_j==67
recode q_a 449=546 if q_j==15
recode q_a 514=515 if q_j==72
recode q_a 462=463 if q_j==15





//encoding and creating categorical and binary variables from demographic charecteristics
encode q_i, gen (gender)

//recoding so graphs look better
recode gender (1=3)

la def gender 3 "Female", modify
la val gender gender

//creating gender dummy for male
gen male=gender


recode male (2=1)(3=0)

la var male "Male"

la def male 0 "No" 1 "Yes", modify
la val male male
order gender, after (q_i)
order male, after (q_i)



rename q_j age


encode district, gen (dis)

recode dis 2=7
recode dis 1=8

la def dis 3 "Dinajpur (Poor)" 4 "Faridpur (Rich)" 5 "Manikganj (Average)" ///
6 "Netrokona (Haor)" 7 "Bhola (Coastal)" 8 "Bandarban (Hill tracts)", modify

order dis, after (district)

encode q_q, gen (region)

order region, after (q_q)


//creating region dummy for rural
gen rural=region

recode rural (2=0)
la var rural "Region is Rural"
la def rural 0 "No" 1 "Yes", modify
la val rural rural

order rural, after (q_q)



encode Ben_NBen, gen (t_ben)
label variable t_ben "Type of respondent"

order t_ben, after (Ben_NBen)

//creating dummy

gen ben1=t_ben

recode ben1 (2=0)

la var ben1 "Respondent is beneficiary"

la def ben1 0 "No" 1 "Yes", modify
la val ben1 ben1



order ben1, after (Ben_NBen)

rename q_t ben_t
label variable ben_t "Type Of beneficiary"

//recoding so that when I make the graph, the bars are arranged in a descending order


recode ben_t (4=7) (5=8)

la def ben_t 1 "Old Citizens" 2 "Widows" 3 "Disabled" 7 "Dis. Edu. Stipend" ///
8 "Marginalised" 6 "Poor Mothers", modify
la val ben_t ben_t




rename q_u ben_n
label variable ben_n "Type Of Non-beneficiary"

//recoding so that when I make the graph, the bars are arranged in a descending order

recode ben_n (5=7) (4=8)

la def ben_n 1 "Old Age Allowance" 2 "Widow Allowance" 3 "Disability Allowance" ///
8 "Edu. Stipend for the Disabled" 7 "Allowance for the Marginalized" ///
6 "Allowance for Poor Mothers", modify
la val ben_n  ben_n

la def ben_n 1 "Old Citizens" 2 "Widows" 3 "Disabled" 8 "Dis. Edu. Stipend" ///
7 "Marginalised" 6 "Poor Mothers", modify


gen ben_tn=ben_t

order ben_tn, after (ben_n)

recode ben_tn (7=4) (8=5)


la def ben_tn 1 "Old Citizens" 2 "Widows" 3 "Disabled" 4 "Dis. Edu. Stipend" ///
5 "Marginalised" 6 "Poor Mothers", modify
la val ben_tn ben_tn


recode ben_tn .=1 if ben_n==1
recode ben_tn .=2 if ben_n==2
recode ben_tn .=3 if ben_n==3
recode ben_tn .=4 if ben_n==8
recode ben_tn .=5 if ben_n==7
recode ben_tn .=6 if ben_n==6


encode category_district, gen (cat_district)
label variable cat_district "Category of district"

order cat_district, after (category_district)

recode cat_district (1=7) (3=8) (2=9)

recode cat_district (4=10)

la def cat_district 10  "Hill tracts" 7 "Average" 8 "Haor" 9 "Coastal", modify
la val cat_district cat_district

recode q_a 448=545 if cat_district==8


encode category_district, gen (cat_district_n)
order cat_district_n, after (category_district)




encode q_v, gen (edu_ben)
label variable edu_ben "Educational Qualification of the respondent"
order edu_ben, after (q_v)

recode edu_ben 4=8
recode edu_ben 5=9
recode edu_ben 3=10
recode edu_ben 1=11
recode edu_ben 6=12
recode edu_ben 2=13
recode edu_ben 7=14

la def edu_ben 8 "No formal education" 9 "Only Religious Education" ///
10 "Less than primary education" 11 "Completed primary education" 12 "SSC" ///
13 "HSC" 14 "University Degree", modify


recode edu_ben (8=1) (9=2) (10=3) (11=4) (12=5) (13=6) (14=7)

la def edu_ben 1 "No formal education" 2 "Only Religious Education" ///
3 "Less than primary education" 4 "Completed primary education" 5 "SSC" ///
6 "HSC" 7 "University Degree", modify




encode s2_1, gen (occ)
label variable occ "Main profession of the respondent"
order occ, after (s2_1)

encode s2_1oth, gen (oth_occ)
order oth_occ, after (s2_1oth)

recode oth_occ 4=.


recode occ 6=14 if oth_occ==1
recode occ 6=15 if oth_occ==2
recode occ 6=16 if oth_occ==3
recode occ 15=10

recode occ 6=17 if oth_occ==5
recode occ 6=18 if oth_occ==6
recode occ 6=19 if oth_occ==7
recode occ 18=10

recode occ 3=2

la def occ 14 "Beggar" 16 "Kabiraj" 17 "Night guard" 19 "Teacher", modify
la val occ occ

la def occ 10 "Skilled labour" 7 "PWD or aged people", modify 


recode occ (7=20) (4=21) (1=22) (13=23) (2=24) (11=25) (12=26) (5=27) (10=28) ///
(9=29) (14=30) (8=31) (16=32) (17=33) (19=34) 


la def occ 20 "PWD or aged people" 21 "House wife" 22 "Daily Labour" ///
23 "Unemployed" 24 "Farmer/Fisherman" 25 "Small business" 26 "Student" ///
27 "Maid servant", modify 

la def occ 28 "Skilled labour" 29 "Rickshaw/Van puller" 30 "Beggar" ///
31 "Teacher" 32 "Restaurant" 33 "Kabiraj" 34 "Night guard", modify

gen occ_check=.
recode occ_check .=1 if occ== 4 | occ==6 | occ==12 | occ==13 | occ==14
recode occ_check .=1 if occ==7


rename s2_2 m_earner
la var m_earner "Main earner of the household"

la def m_earner 1 "Yes" 2 "No"
la val m_earner m_earner


gen r_emp=.
recode r_emp .=1 if m_earner!=.

//Coding beggars and maid servants as not employed due to income criteria of SSNs
recode r_emp 1=2 if occ==30 | (ben_tn==6 & occ==27) 

recode r_emp .=2 if m_earner==. 

order r_emp, before (m_earner)

la var r_emp "Employment status"


la def r_emp 1 "Employed" 2 "Unemployed", modify
la val r_emp r_emp

gen n_emp=r_emp

recode n_emp (2=0)

la def n_emp 0 "No" 1 "Yes", modify
la val n_emp n_emp

la var n_emp "Respondent is employed"




recode m_earner 1=2 if occ==30
recode m_earner 2=. if occ==30
recode r_emp 1=2 if occ==30
recode r_emp 2=. if occ==30
recode r_emp .=2 if occ==30

gen mn_earner=m_earner

la def mn_earner 1 "Main" 2 "Not main", modify
la val mn_earner mn_earner


encode s2_3, gen (remittance)
la var remittance "Does the household receive any remittance?"
order remittance, after (s2_3)

/*Recoding 1 as 3 because 1 is no in the dataset and when I create the graph, no 
is shown before yes which does not look good recode remittance 1=3*/


la def remittance 3 "No", modify 

//New variable created to properly label the graph bars

gen n_rem=remittance

la def n_rem 2 "Receives" 3 "Does not receive"
la val n_rem n_rem

rename s2_4 a_remittance
la var a_remittance "Amount of remittance (monthly)" 

recode a_remittance .=0 if a_remittance>0

/*Creating category of remittance to make graph bars with different categories
and frequencies*/

gen a_remit=.
recode a_remit .=1 if inrange(a_remittance,0,4000)
recode a_remit .=2 if inrange(a_remittance,4001,8000)
recode a_remit .=3 if inrange(a_remittance,8001,12000)
recode a_remit .=4 if inrange(a_remittance,12001,16000)
recode a_remit .=5 if inrange(a_remittance,16001,20000)


order a_remit, after (a_remittance)

la def a_remit 1 "BDT 0-4,000" 2 "BDT 4,001-8,000" 3 "BDT 8,001-12,000" ///
4 " BDT 12,001-16,000" 5 "BDT 16,001-20,000"

la val a_remit a_remit

la var a_remit "Category of remittance"

rename s2_5 f_w_worker
la var f_w_worker "Family member working for daily wages"


//Encoding the string variable to create binary variable

encode f_w_worker, gen (fw_worker)
order fw_worker, after (f_w_worker)


recode fw_worker (1=3)
recode fw_worker (3=0)

la def fw_worker 0 "No", modify
la val fw_worker fw_worker


recode fw_worker (2=1)

la def fw_worker 1 "Yes", modify
la val fw_worker fw_worker


//creating new variable with different labels so the graphs look better

gen fn_worker=fw_worker

la def fn_worker 2 "Works for daily wage" 3 "Does not work", modify
la val fn_worker fn_worker

order fn_worker, after (fw_worker)



//Encoding the string variable to create categorical and binary variable
encode s2_6, gen (own_house)

recode own_house 1=3

la def own_house 3 "No", modify

la var own_house "Ownership of the house they live in"

order own_house, after (s2_6)

encode s2_6, gen (own_house_n)


order own_house_n, after (s2_6)

recode own_house_n 1=0

la def own_house_n 0 "No", modify


recode own_house_n 2=1

la def own_house_n 1 "Yes", modify


la var own_house_n "Ownership of the house they live in"



rename s2_7 m_rent
la var m_rent "Monthly rent (house)"



rename s2_8 n_rooms
la var n_rooms "No. of rooms in the HH"

gen b_rooms=1
recode b_rooms 1=0 if inrange(n_rooms,0,2)

la var b_rooms "No. of rooms more than two"
la def b_rooms 0 "No" 1 "Yes", modify
la val b_rooms b_rooms

order b_rooms, after (n_rooms)

encode s2_9, gen (mat_wall)
order mat_wall, after (s2_9)
la var mat_wall "Primary material of the walls of the house"


/*Recoding the material of the house so that when I produce the graph, the bars
are in descending order*/

recode mat_wall (1=6) (3=7) (4=8) (2=9)
la def mat_wall 5 "Corrugated iron sheet" 6 "Brick" 7 "Soil" 8 "Straw" 9 "Bamboo", modify
la val mat_wall mat_wall

/*Generating a binary variable which is 0 when the wall is not inadequate and 1
when it is inadequate as per the multidimensional poverty index definitions*/
gen in_wall=.
recode in_wall .=0 if mat_wall ==6
recode in_wall .=1 if mat_wall !=6

la def in_wall 0 "No" 1 "Yes", modify
la val in_wall in_wall


la var in_wall "Inadequate wall"

order in_wall, after (mat_wall)


encode s2_10, gen (mat_roof)
order mat_roof, after (s2_10)
la var mat_roof "Primary material of the roof of the house"


/*Recoding the material of the roof so that when I produce the graph, the bars
are in descending order*/


recode mat_roof (1=5) (2=6) (3=7)

la def mat_roof 4 "Corrugated iron sheet" 5 "Concrete" 6 "Polythene" 7 "Soil", modify
la val mat_roof mat_roof

recode mat_roof 7=4

la def mat_roof 4 "C.I. sheet/Soil", modify


/*Generating a binary variable which is 0 when the roof is not inadequate and 1
when it is inadequate as per the multidimensional poverty index definitions*/

encode s2_10, gen (mat_roof_n)
order mat_roof_n, after (s2_10)

recode mat_roof_n (4=1) (3=2)

recode mat_roof_n (1=0)

recode mat_roof_n (2=1)

rename mat_roof_n in_roof

la def in_roof 0 "No" 1 "Yes", modify
la val in_roof in_roof

la var in_roof "Inadequate roof"


gen in_one=1
recode in_one 1=0 if in_wall==0 & in_roof==0

la def in_one 0 "No" 1 "Yes", modify
la val in_one in_one

la var in_one "Inadequate housing material in at least one"


/*Creating a binary variable for inadequate/deprived toilet where if the answer
is 0 the toilet is not inadequate and 1 if the toilet is inadequate as per MDPI
classifications*/

encode s2_11, gen (t_toilet)
order t_toilet, after (s2_11)
la var t_toilet "Type of latrine"

recode t_toilet (4=6)


la def t_toilet 1 "Flush toilet" 2 "Open pit" 3 "Pit latrine" ///
5 "No facility/Bush" 6 "Hanging toilet", modify

la val t_toilet t_toilet

rename t_toilet in_toilet

recode in_toilet (1=0) (3=0)

recode in_toilet (2=1) (5=1) (6=1)


la def in_toilet 0 "No" 1 "Yes", modify
la val in_toilet in_toilet


la var in_toilet "Deprived toilet"

rename s2_12 n_fans
la var n_fans "No. of fans"


gen b_fans=1
recode b_fans 1=0 if inrange(n_fans,0,1)

la var b_fans "No. of fans more than one"
la def b_fans 0 "No" 1 "Yes", modify
la val b_fans b_fans

order b_fans, after (n_fans)


//Creating categorical and binary variables for cycle ownership

encode s2_13, gen (own_cycle)
order own_cycle, after (s2_13)
la var own_cycle "Ownership of cycle or any motor vehicle"

recode own_cycle 1=3


la def own_cycle 3 "No", modify
la val own_cycle own_cycle

la def own_cycle 2 "Owns cycle/motor vehicle" 3 "Does not own", modify


recode own_cycle (3=0) (2=1)

la def own_cycle 0 "No" 1 "Yes", modify
la val own_cycle own_cycle


rename s2_14 a_land
la var a_land "Arable land (decimal)"


//Generate categories for quantities of land ownership to make graph bars

gen ad_land=.
recode ad_land 1=0 if a_land==0
recode ad_land .=1 if inrange(a_land,0,20)
recode ad_land .=2 if inrange(a_land,21,40)
recode ad_land .=3 if inrange(a_land,41,60)
recode ad_land .=4 if inrange(a_land,61,80)
recode ad_land .=5 if inrange(a_land,81,100)
recode ad_land .=6 if inrange(a_land,101,120)
recode ad_land .=7 if inrange(a_land,121,140)
recode ad_land .=8 if inrange(a_land,141,160)


la def ad_land 0 "0" 1 "1-20" 2 "21-40" 3 "41-60" 4 "61-80" 5 "81-100" ///
6 "101-120" 7 "121-140" 8 "141-160", modify
la val ad_land ad_land

order ad_land, after (a_land)


la var ad_land "Quantity of land (categorized)"

gen own_l=.
recode own_l .=0 if inrange(a_land,0,50)
recode own_l .=1 if inrange(a_land, 51, 160)

//for graphs
gen sps_la=.
recode sps_la .=0 if a_land==0
recode sps_la .=1 if inrange(a_land,1,50)
recode sps_la .=2 if inrange(a_land, 51, 160)

la def sps_la 0 "Zero" 1 "One-Fifty" 2 "Fifty one-One sixty"
la val sps_la sps_la



la def own_l 0 "No" 1 "Yes", modify
la val own_l own_l

la var own_l "Owns more than 50 decimals of land"





rename s2_15 n_tv
la var n_tv "No. of TV"


la def n_tv 0 "No" 1 "Yes", modify
la val n_tv n_tv


gen sps_tv=.

recode sps_tv .=0 if n_tv==0
recode sps_tv .=7 if n_tv==1




rename s2_16 n_bphone
la var n_bphone "No. of button phone"

gen n_bphone_n=.
recode n_bphone_n .=0 if inrange(n_bphone, 0, 1)
recode n_bphone_n .=1 if inrange(n_bphone, 2, 4)

la var n_bphone_n "Button phone more than one"

la def n_bphone_n 0 "No" 1 "Yes", modify
la val n_bphone_n n_bphone_n

order n_bphone_n, after (n_bphone)

rename s2_17 n_sphone
la var n_sphone "No. of smart phone"



gen n_sphone_n=.
recode n_sphone_n .=0 if n_sphone==0
recode n_sphone_n .=1 if inrange(n_sphone, 1, 4)

la var n_sphone_n "Smart phone more than zero"

la def n_sphone_n 0 "No" 1 "Yes", modify
la val n_sphone_n n_sphone_n

order n_sphone_n, after (n_sphone)

//finding the total number of phones in a hh
egen n_phone =rowtotal (n_bphone n_sphone)

order n_phone, after(n_sphone_n)

rename s2_18 n_laptop
la def n_laptop 0 "No" 1 "Yes", modify
la val n_laptop n_laptop

la var n_laptop "Owns laptop/computer"



/*creating asset index taking the MDPI classification as the basis and with
modifications based on available and updated variables. Land ownership is a 
significant asset and hence it is taken separately*/


gen asset_in=0

//land
recode asset_in 0=1 if own_l==1

//cycle and others
recode asset_in 0=1 if own_cycle==1 & n_tv==1
recode asset_in 0=1 if own_cycle==1 & n_bphone_n==1
recode asset_in 0=1 if own_cycle==1 & n_sphone_n==1
recode asset_in 0=1 if own_cycle==1 & n_laptop==1

//tv and others
recode asset_in 0=1 if n_tv==1 & n_bphone_n==1
recode asset_in 0=1 if n_tv==1 & n_sphone_n==1
recode asset_in 0=1 if n_tv==1 & n_laptop==1


//button phone and others
recode asset_in 0=1 if n_bphone_n==1 & n_sphone_n==1
recode asset_in 0=1 if n_bphone_n==1 & n_laptop==1

//smart phone and others
recode asset_in 0=1 if n_sphone_n==1 & n_laptop==1



gen asset_in_n=.
recode asset_in_n .=0 if asset_in==1
recode asset_in_n .=1 if asset_in==0


la var asset_in_n "HH is deprived in terms of assets"


la def asset_in_n 0 "No" 1 "Yes", modify
la val asset_in_n asset_in_n





encode s3_1, gen (know_ssn)
la var know_ssn "knowledge about digital SS payments"
order know_ssn, after (s3_1)

recode know_ssn 1=3
recode know_ssn 2=4
recode know_ssn 4=1
recode know_ssn 3=2

la def know_ssn 1 "Yes" 2 "No", modify

rename s3_2 name_ssn
la var name_ssn "Name all SSN eligible for digital delivery"
la def name_ssn 1 "Yes" 2 "No" 
la val name_ssn name_ssn

encode s3_4, gen (reg_ssn)
la var reg_ssn "Reg. process for SSN"
order reg_ssn, after (s3_4)

recode reg_ssn 3=.

la def reg_ssn 1 "Someone did the reg. for me" ///
2 "Submission of docs to gov. rep." 6 "Completed by going to office", modify

recode reg_ssn 5=6
recode reg_ssn (1=7) (4=8)


la def reg_ssn 7 "Someone did the reg. for me" 8 "Online (By someone else)", modify


la def s3_5_2 1 "Yes" 2 "No", modify
la val s3_5_2 s3_5_2

recode s3_5_2 0=2

recode s3_5_2 2=. if ben_n!=.

recode s3_5_5 0=2

la def s3_5_5 1 "Yes" 2 "No", modify
la val s3_5_5 s3_5_5

recode s3_5_5 2=. if ben_n!=.

rename s3_6 ver_doc
la def ver_doc 1 "Yes" 2 "No" 88 "Do not know", modify
la var ver_doc "Local admin. verification of docs"

rename s3_7 miss_doc
la def miss_doc 1 "Yes" 2 "No", modify
la var miss_doc "Missing docs"


encode s3_8, gen (acq_doc)
la var acq_doc "Process of reg. with missing docs"
order acq_doc, after (s3_8)


rename s3_9 add_help
la def add_help 1 "Yes" 2 "No"

rename s3_11 infor_fee
rename infor_fee reg_fee

la var reg_fee "Informal fee for registration"
la def reg_fee 1 "Yes" 2 "No"
la val reg_fee reg_fee

gen ask_fee=0
order ask_fee, after (reg_fee)

recode ask_fee 0=1 if reg_fee==1

recode ask_fee 0=1 if s3_19_1==1 | s3_21_9==1

la var ask_fee "Asked for informal fee"




la def ask_fee 0 "No" 1 "Yes", modify
la val ask_fee ask_fee





gen cd_pay=.
recode cd_pay .=1 if reg_fee==1
recode cd_pay .=0 if s3_19_1==1 | s3_21_9==1
order cd_pay, after (reg_fee)


la def cd_pay 0 "No" 1 "Yes", modify
la val cd_pay cd_pay

la var cd_pay "Could pay informal fee"

rename s3_12 amt_fee
la var amt_fee "Amount of informal fee"



gen fee_groups=.
recode fee_groups .=1 if inrange(amt_fee,0,3000)
recode fee_groups .=2 if inrange(amt_fee,3001,6000)
recode fee_groups .=3 if inrange(amt_fee,6001,9000)

la val fee_groups fee_groups
la def fee_groups 1 "BDT 0-3000" 2 "BDT 3001-6000" 3 "BDT 6001-9000", modify


encode s3_13, gen (pay_whom)
order pay_whom, after (s3_13)
recode pay_whom (4=3)
recode pay_whom (5=.)
recode pay_whom (1=6)

la val pay_whom pay_whom
la def pay_whom 2 "Local govt. representative" 3 "Local politician" ///
6 "Upazilla level govt. official", modify


rename s3_14 oth_val
la var oth_val "Require validation of other local politican"
la val oth_val oth_val
la def oth_val 1 "Yes" 2 "No"

gen oth_ch=.
recode oth_ch .=1 if s3_15_2==1
recode oth_ch .=1 if s3_15_3==1

recode oth_ch 1=0 if s3_15_1==1
recode oth_ch 1=0 if s3_15_4==1


gen oth_val2=oth_val


recode oth_val 1=2 if oth_ch==1

recode s3_20_1 (1=.) (0=.) if ben1==1
recode s3_20_2 (1=.) (0=.) if ben1==1
recode s3_20_3 (1=.) (0=.) if ben1==1
recode s3_20_4 (1=.) (0=.) if ben1==1
recode s3_20_5 (1=.) (0=.) if ben1==1
recode s3_20_6 (1=.) (0=.) if ben1==1
recode s3_20_88 (1=.) (0=.) if ben1==1


recode s3_20_1 0=2

la def s3_20_1 1 "Yes" 2 "No"
la val s3_20_1 s3_20_1

recode s3_20_4 0=2

la def s3_20_4 1 "Yes" 2 "No"
la val s3_20_4 s3_20_4


recode s3_20_2 0=2

la def s3_20_2 1 "Yes" 2 "No"
la val s3_20_2 s3_20_2






recode s3_21_98 0=2

la def s3_21_98 1 "Yes" 2 "No"
la val s3_21_98 s3_21_98




encode s4_1, gen (pmt_steps)
la var pmt_steps "Steps to receive SSN"
order pmt_steps, after (s4_1)

recode pmt_steps 5=.

recode pmt_steps (2=3) (7=8)
la def pmt_steps 3 "Go to local gov. official/rep." ///
8 "Take help from hh member/relative/friend", modify
la val pmt_steps pmt_steps

recode pmt_steps (1=9) (3=10) (8=11)
la def pmt_steps 9 "Formal bank" 10 "Go to local gov. official/rep." ///
11 "Take help from hh member/relative", modify
la def pmt_steps 11 "Assisted by hh member/relative", modify
la def pmt_steps 4 "Go to mobile banking agent", modify

rename s4_2 process_smooth
la var process_smooth "Ease of process"
la def process_smooth 1 "Very smooth" 2 "Smooth" 3 "Neutral" 4 "Complex" 5 "Very complex"
rename process_smooth ease_pro


la def ease_pro 1 "Very smooth" 2 "Smooth" 3 "Neutral" 4 "Complex" 5 "Very complex", modify
la val ease_pro ease_pro

ta ease_pro

rename s4_3 pmt_rgr
la var pmt_rgr "Regularity of payments"
la def pmt_rgr 1 "Yes" 2 "No"
la val pmt_rgr pmt_rgr

rename s4_4 pmt_help
la var pmt_help "Do you seek help from anyone?"
la def pmt_help 1 "Yes" 2 "No"
la val pmt_help pmt_help

rename s4_5 pmthelp_who
la var pmthelp_who "To whom do you approach?"
la def pmthelp_who 1 "Local govt representative" 2 "Mobile Banking Agent" ///
3 "Local politician" 4 "Govt. officer" 99 "Others (Specify)"


la def s4_8 1 "Yes" 2 "No"
la val s4_8 s4_8

la def s4_10 1 "Yes" 2 "No" 98 "Not applicable"
la val s4_10 s4_10

la var s4_10 "Faces problem in receiving digital payments"



gen dig_pmt=1
recode dig_pmt 1=2 if s4_10==98
recode dig_pmt 1=. if ben_n!=.

la def dig_pmt 1 "Yes" 2 "No"
la val dig_pmt dig_pmt

la var dig_pmt "Receives payment digitally"


encode s5_1, gen (reg_how) 
order reg_how, after (s5_1)

recode reg_how (1=3)
la def reg_how 3 "No", modify
la val reg_how reg_how


encode s5_2, gen (reg_rules) 
order reg_rules, after (s5_2)

recode reg_rules (2=4) (1=5)

la def reg_rules 3 "Yes" 4  "Partially" 5 "No", modify
la val reg_rules reg_rules


encode s5_3, gen (op_own) 
order op_own, after (s5_3)

recode op_own (1=.) (2=5) (3=6)

la def op_own 5 "No" 6 "Does not get payments digitally", modify
la val op_own op_own


recode op_own 6=.

recode op_own .=6 if s5_3=="Not applicable"

recode s4_10 .=98 if op_own==6



la def s5_4 1 "Yes" 2 "No"
la val s5_4 s5_4


encode s5_5, gen (op_who) 
order op_who, after (s5_5)

recode op_who (5=.)

recode op_who (3=9) (2=10) (8=11) (1=12) (4=13) (6=14)

la def op_who 9 "Grandchild" 10 "Father/Mother" 11 "Son/Daughter-in-law" ///
12 "Brother/Sister" 13 "Husband/Wife" 14 "Others", modify
la val op_who op_who

encode s5_7, gen (cap_dig) 
order cap_dig, after (s5_7)

recode cap_dig (1=3)

la def cap_dig 3 "No", modify
la val cap_dig cap_dig


encode s5_8, gen (rcpt_how) 
order rcpt_how, after (s5_8)

recode rcpt_how (7=4)
recode rcpt_how (1=.) (2=5) (3=6)


la def rcpt_how 4 "HH members/relatives receive it" 5 "Not applicable" ///
6 "Others", modify
la val rcpt_how rcpt_how

recode rcpt_how (6=4)


encode s5_12, gen (app_ask) 
order app_ask, after (s5_12)
recode app_ask (1=3)

la def app_ask 3 "No", modify
la val app_ask app_ask


encode s5_13, gen (trn_ssn) 
order trn_ssn, after (s5_13)

recode trn_ssn (1=3)

la def trn_ssn 3 "No", modify
la val trn_ssn trn_ssn



///Factor analysis
global xlist3 own_cycle b_fans b_rooms n_tv n_bphone_n n_sphone_n n_laptop 
global id q_a
global ncomp 1




corr $xlist3


* Factor analysis
factor $xlist3

* Scree plot of the eigenvalues
screeplot
screeplot, yline(1)


* Factor analysis (pf principal factors, pcf principal component factors)
factor $xlist3, mineigen(1)
factor $xlist3, factor($ncomp) 
factor $xlist3, factor($ncomp) blanks(0.3)
factor $xlist3, factor($ncomp) pcf
* Scatter plots of the loadings and score variables
///one factor retained loadingplot
//one factor retained scoreplot

* Scores of the components
predict f1

summ f1


gen nor_f1=(f1-(-1.3053141))/(3.034322-(-1.3053141))

* KMO measure of sampling adequacy
estat kmo








//creating a dummy for hill tracts 
gen hill=0

recode hill 0=1 if cat_district==10

la def hill 1 "Yes" 0 "No", modify
la val hill hill


//dropping employed individuals

tempfile ssn

save `ssn'

drop if n_emp==1



//regression model
global ylist ask_fee

global xlist rural hill ben1 i.ben_tn a_remittance nor_f1 a_land


global xlist2 a_remittance nor_f1 a_land


//logit on probability of being beneficiary

logit ben1 $xlist2


* Marginal effects (at the mean)

quietly logit ben1 $xlist2 
margins, dydx(*) atmeans



//correctly predicted values

quietly logit ben1 $xlist2
estat classification




//logit on asked for informal fee

logit $ylist $xlist


* Marginal effects (at the mean)

quietly logit $ylist $xlist  
margins, dydx(*) atmeans

//correctly predicted values

quietly logit $ylist $xlist
estat classification



use `ssn', clear

